package com.iotproject.guli;

import com.aliyun.oss.ClientException;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.vod.model.v20170321.*;

public class test {
    //填入AccessKey信息
    public static DefaultAcsClient initVodClient(String accessKeyId, String accessKeySecret) throws ClientException {
        String regionId = "cn-shanghai";  // 点播服务接入地域
        DefaultProfile profile = DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret);
        DefaultAcsClient client = new DefaultAcsClient(profile);
        return client;
    }
    /*获取播放地址函数*/
    public static GetPlayInfoResponse  getPlayInfo(DefaultAcsClient client) throws Exception {
        GetPlayInfoRequest request = new GetPlayInfoRequest();
        request.setVideoId("608d557ed2df71eebfdb0764a0ec0102");
//        request.setEndpoint("vod.cn-shenzhen.aliyuncs.com");
        return client.getAcsResponse(request);
    }

    /*获取播放凭证函数*/
    public static GetVideoPlayAuthResponse getVideoPlayAuth(DefaultAcsClient client) throws Exception {
        GetVideoPlayAuthRequest request = new GetVideoPlayAuthRequest();
        request.setVideoId("2036ec49d65771eebf9f5017e1e90102");
//        request.setEndpoint("vod.cn-shenzhen.aliyuncs.com");
        return client.getAcsResponse(request);
    }

    public static DeleteVideoResponse deleteVideo(DefaultAcsClient client) throws Exception {
        DeleteVideoRequest request = new DeleteVideoRequest();
        //支持传入多个视频ID，多个用逗号分隔
        request.setVideoIds("608d557ed2df71eebfdb0764a0ec0102");
        request.setEndpoint("vod.cn-shenzhen.aliyuncs.com");
        return client.getAcsResponse(request);
    }

    /*以下为调用示例*/
    public static void main(String[] argv) {
        //获取视频播放地址
//        DefaultAcsClient client = initVodClient("LTAI5t6rSyqojMmXfoDE3jf4","6R7tZg6fA91RWFVs1XZJZLlXCWFnKC");
//        GetPlayInfoResponse response = new GetPlayInfoResponse();
//        try {
//            response = getPlayInfo(client);
//            List<GetPlayInfoResponse.PlayInfo> playInfoList = response.getPlayInfoList();
//            //播放地址
//            for (GetPlayInfoResponse.PlayInfo playInfo : playInfoList) {
//                System.out.print("PlayInfo.PlayURL = " + playInfo.getPlayURL() + "\n");
//            }
//            //Base信息
//            System.out.print("VideoBase.Title = " + response.getVideoBase().getTitle() + "\n");
//        } catch (Exception e) {
//            System.out.print("ErrorMessage = " + e.getLocalizedMessage());
//        }
//        System.out.print("RequestId = " + response.getRequestId() + "\n");

        //获取视频播放凭证
        DefaultAcsClient client = initVodClient("LTAI5t6rSyqojMmXfoDE3jf4","6R7tZg6fA91RWFVs1XZJZLlXCWFnKC");
        GetVideoPlayAuthResponse response = new GetVideoPlayAuthResponse();
        try {
            response = getVideoPlayAuth(client);
            //播放凭证
            System.out.print("PlayAuth = " + response.getPlayAuth() + "\n");
            //VideoMeta信息
            System.out.print("VideoMeta.Title = " + response.getVideoMeta().getTitle() + "\n");
        } catch (Exception e) {
            System.out.print("ErrorMessage = " + e.getLocalizedMessage());
        }
        System.out.print("RequestId = " + response.getRequestId() + "\n");

        //删除视频
//        DefaultAcsClient client = initVodClient("LTAI5tPVMx7rUaDqgBC6Cd1C","AI3WLaZmET9bADQsXwLJvnChXFsRrn");
//        DeleteVideoResponse response = new DeleteVideoResponse();
//        try {
//            response = deleteVideo(client);
//        } catch (Exception e) {
//            System.out.print("ErrorMessage = " + e.getLocalizedMessage());
//        }
//        System.out.print("RequestId = " + response.getRequestId() + "\n");
    }

}
